package com.enbatis.mybatisplugs.controller;

import com.enbatis.mybatisplugs.base.BaseController;
import com.enbatis.mybatisplugs.commons.sql.Wrapper;
import com.enbatis.mybatisplugs.commons.utils.ResultReturn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.enbatis.mybatisplugs.entity.TRecord;
import com.enbatis.mybatisplugs.service.TRecordService;


import java.util.List;

@RestController
@RequestMapping("v1/t_record")
public class TRecordController extends BaseController {

@Autowired
private TRecordService tRecordService;


    @PostMapping("/add")
    public ResultReturn<TRecord> add(@RequestBody TRecord tRecord){
        return  success(tRecordService.insert(tRecord));
    }


    @DeleteMapping("/delete")
    public ResultReturn<Integer> delete(@RequestParam("id") Long id){
        return success(tRecordService.deleteById(id));
    }


    @PutMapping("/{id}")
    public  ResultReturn<Integer> update(@PathVariable("id") Long id,@RequestBody TRecord tRecord){
        tRecord.setId(id);
        return success(tRecordService.updateById(tRecord));
    }


    @GetMapping("/{id}")
    public ResultReturn<TRecord> get(@PathVariable("id") Long id) {
        return success(tRecordService.getById(id));
    }


    @GetMapping("/list")
    public ResultReturn<List<TRecord>> getList(TRecord tRecord){
        return success(tRecordService.list(new Wrapper<>(tRecord)));
    }

}
